import axios from "axios";
// import { Toast } from "vant";

// 创建axios实例
const $http = axios.create({
    timeout: 10000,
    headers: {
        "Content-Type": 'application/json;charset=UTF-8'
    }
})

// aixos请求拦截器
$http.interceptors.request.use(
    config => {
        config.headers = {}
        if (localStorage.getItem('Cusertoken')) {
            config.headers.Authorization = localStorage.getItem('Cusertoken') || ""
        }
        return config
    },
    error => {
        return Promise.reject(error)
    }
)

// axios响应拦截器
$http.interceptors.response.use(
    response => {
        const { data, config } = response
        // console.log(data, config);
        return data
    },
    error => {
        return Promise.reject(error)
    }
)

export default $http